home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Anvil.lua < prev    next >
Text File  |  2010-08-31  |  4KB  |  120 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Anvil + Projectile Anvil
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.anvil={}
  10. cc.anvil.anvil={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.anvil.gfx_wpn=loadgfx("weapons/rc.bmp")                            -- Weapon Image
  14. setmidhandle(cc.anvil.gfx_wpn)
  15. cc.anvil.gfx_pro=loadgfx("weapons/anvil.bmp")                        -- Projectile Image
  16. setmidhandle(cc.anvil.gfx_pro)
  17. cc.anvil.sfx_hit=loadsfx("buildmetal.ogg")
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: anvil
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.anvil.id=addweapon("cc.anvil","Anvil",cc.anvil.gfx_pro,0,3)        -- Add Weapon (0 uses, first in round 3)
  24.  
  25. function cc.anvil.draw()                                            -- Draw
  26.     setblend(blend_alpha)
  27.     setalpha(1)
  28.     setcolor(255,255,255)
  29.     drawinhand(cc.anvil.gfx_wpn,7,0)
  30.     -- HUD Positioning
  31.     if weapon_shots==0 then
  32.         hudpositioning(pos_invisible)
  33.     end
  34. end
  35.  
  36. function cc.anvil.attack(attack)                                    -- Attack
  37.     if (weapon_shots<=0) and (weapon_position==1) then
  38.         -- No more weapon switching!
  39.         useweapon(0)
  40.         --playsound(cc.anvil.sfx_attack)
  41.         weapon_shots=weapon_shots+1
  42.         -- Attack
  43.         pid=createprojectile(cc.anvil.anvil.id)
  44.         projectiles[pid]={}
  45.         projectiles[pid].x=weapon_x
  46.         projectiles[pid].y=-500
  47.         projectiles[pid].sx=0
  48.         projectiles[pid].sy=3.0
  49.         -- End Turn
  50.         endturn()
  51.     end
  52. end
  53.  
  54. --------------------------------------------------------------------------------
  55. -- Projectile: anvil
  56. --------------------------------------------------------------------------------
  57.  
  58. cc.anvil.anvil.id=addprojectile("cc.anvil.anvil")    -- Add Projectile
  59.  
  60. function cc.anvil.anvil.draw(id)                            -- Draw
  61.     -- Setup draw mode
  62.     setblend(blend_alpha)
  63.     setalpha(1)
  64.     setcolor(255,255,255)
  65.     setscale(1,1)
  66.     setrotation(0)
  67.     -- Draw projectile
  68.     drawimage(cc.anvil.gfx_pro,projectiles[id].x,projectiles[id].y)
  69. end
  70.  
  71. function cc.anvil.anvil.update(id)                            -- Update
  72.     -- Particle Tail
  73.     particle(p_smoke,projectiles[id].x,projectiles[id].y)
  74.     particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  75.     particlefadealpha(0.05)
  76.     -- Gravity influence on speed
  77.     projectiles[id].sy=projectiles[id].sy+getgravity()
  78.     -- Move (in substep loop for optimal collision precision)
  79.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/2)
  80.     msubx=projectiles[id].sx/msubt
  81.     msuby=projectiles[id].sy/msubt
  82.     for i=1,msubt,1 do
  83.         projectiles[id].x=projectiles[id].x+msubx
  84.         projectiles[id].y=projectiles[id].y+msuby
  85.         -- Collision
  86.         if collision(cc.anvil.gfx_pro,projectiles[id].x,projectiles[id].y)==1 then
  87.             if playercollision()~=0 then
  88.                 playerdamage(playercollision(),10000)
  89.                 playsound(sfx_splatter2)
  90.             else
  91.                 if objectcollision()~=0 then
  92.                     objectdamage(objectcollision(),10000)
  93.                 end
  94.                 -- Destroy terrain
  95.                 terrainexplosion(projectiles[id].x,projectiles[id].y,25,1)
  96.                 playsound(cc.anvil.sfx_hit)
  97.                 -- Particles
  98.                 for j=1,30,1 do
  99.                     particle(p_smoke,projectiles[id].x,projectiles[id].y)
  100.                     particlespeed(math.random(-10,10)*0.1,math.random(-10,10)*0.1)
  101.                     particlefadealpha(0.01)
  102.                 end
  103.                 -- Free projectile
  104.                 freeprojectile(id)
  105.                 break
  106.             end
  107.         end
  108.         -- Water
  109.         if (projectiles[id].y)>getwatery()+5 then
  110.             -- Effects
  111.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  112.             playsound(sfx_hitwater1)
  113.             -- Free projectile
  114.             freeprojectile(id)
  115.             break
  116.         end
  117.     end
  118.     -- Scroll to projectile
  119.     scroll(projectiles[id].x,projectiles[id].y)
  120. end